package com.solo.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
 * FileName: UserService.java
 * Description: 用户服务 - 使用Setter方法注入
 * Author:   woolflighthouse@163.com
 * Date:     2025-11-19 17:40
 */
@Service
public class UserService {
    private BlogService blogService;

    // 默认构造方法
    public UserService() {
        System.out.println("UserService 已创建");
    }

    // Setter方法注入：可选依赖
    @Autowired
    public void setBlogService(BlogService blogService) {
        this.blogService = blogService;
        System.out.println("BlogService 已通过Setter方法注入到 UserService");
    }

    public void registerUser(String username) {
        System.out.println("注册用户: " + username);

        // 如果blogService被注入，就为用户创建默认博客
        if (blogService != null) {
            blogService.createBlog(username + "的个人博客");
        }
    }
}
